package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.IUserDao;
import com.cn.wanxi.model.OrdbyModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.util.GetSqlSession;

import java.util.List;


public class UserDaompl implements IUserDao {


    @Override
    public int add(UserModel userModel) {
        int count= GetSqlSession.getSqlSession().insert("com.cn.wanxi.dao.IUserDao.add",userModel);
        return count;
    }

    @Override
    public UserModel FindByUsername(String username) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.FindByUsername",username);
    }


    @Override
    public int findByUsernameAndPassword(UserModel userModel) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.findByUsernameAndPassword",userModel)==null?0:1;//或者可以在sql里面使用count来得到条数进行判断
    }

    @Override
    public int deletebyid(int id) {
        return GetSqlSession.getSqlSession().delete("com.cn.wanxi.dao.IUserDao.deletebyid",id);
    }

    @Override
    public UserModel finById(int id) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.finById",id);
    }

    @Override
    public int update(UserModel userModel) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.IUserDao.update",userModel);
    }

    @Override
    public List<UserModel> findAllBySon(UserModel userModel) {
        System.out.println(userModel.getOrdbyModel());
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.IUserDao.findAllBySon",userModel);

    }

    @Override
    public int getCount(UserModel userModel) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IUserDao.getCount",userModel);

    }

}
